

from rest_framework import serializers

from areas.models import Area


class AreaSerializer(serializers.ModelSerializer):
    """
    省份信息序列化器
    # [{"id":110000,"name":"北京市"},{"id":120000,"name":"天津市"},{"id":130000,"name":"河北省"}
    # 这个序列化器 只是 有 id,name
    """

    class Meta:

        model = Area

        fields = ['id','name']



class SubAreaSerializer(serializers.ModelSerializer):
    """
    市区县序列化器
    # 市,区县
    #[Area,Area,Area]
    # s = AreaSerializer(areas,many=True)
    """
    subs = AreaSerializer(many=True,read_only=True)

    class Meta:
        model = Area

        fields = ['id','name','subs']



